package com.kinon.tyjaccount.tools;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class HttpTools {
	Context context;
	AsyncHttpClient client=new AsyncHttpClient();
	
	public HttpTools(Context context) {
		super();
		client.setTimeout(5*1000);
		this.context = context;
	}
	public HttpTools(Context context,int outTime) {
		super();
		client.setTimeout(outTime);
		this.context = context;
	}
	/**登录请求 */
	public void login(String username, String password,String type,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("username", username);
		params.put("password", password);
		params.put("type", type);
		client.post(context, Url.loginUrl, params, backcall);
	}
	/**订单详情 */
	public void getDetail(String token, String orderno,String dayno,String orderid,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderno", orderno);
		params.put("dayno", dayno);
		params.put("orderid", orderid);
		client.post(context, Url.getDetail, params, backcall);
	}
	/**确认收货 */
	public void updateOrder(String token, String orderid,String state,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		params.put("state", state);
		client.post(context, Url.updateOrder, params, backcall);
	}
	/**早餐、晚餐订单保存 */
	public void saveOrder(String token, String total,String data,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("total", total);
		params.put("data", data);
		client.post(context, Url.saveOrder, params, backcall);
	}
	/**早餐、晚餐支付 */
	public void otherPay(String token, String orderid,String no,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		params.put("no", no);
		client.post(context, Url.otherPay, params, backcall);
	}
	/**午餐支付 */
	public void lunchPay(String token, String no,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("no", no);
		client.post(context, Url.lunchPay, params, backcall);
	}
	/**无商品保存订单 */
	public void saveNewOrder(String token, String total,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("total", total);
		client.post(context, Url.saveNewOrder, params, backcall);
	}
	/**订单列表 */
	public void getOrders(String token, String page,String offset,String type,
						  JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("page", page);
		params.put("offset", offset);
		params.put("type", type);
		client.post(context, Url.getOrders, params, backcall);
	}
	/**退款 */
	public void refund(String token, String orderid,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.refund, params, backcall);
	}
	/**打印 */
	public void printOrder(String token, String orderid,
						   JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.printOrder, params, backcall);
	}
	/**订单详情 */
	public void detail(String token, String orderid,
					   JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.detail, params, backcall);
	}
	/**通知*/
	public void noticeUser(String token, String orderid,
					   JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.noticeUser, params, backcall);
	}
	/**一键通知*/
	public void noticeAllUsers(String token, JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		client.post(context, Url.noticeAllUsers, params, backcall);
	}
	/**工作人员信息 */
	public void info(String token,
					 JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		client.post(context, Url.info, params, backcall);
	}
	/**返回后取消订单 */
	public void cancelOrder(String token,String orderid,
					 JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.cancelOrder, params, backcall);
	}
	/**获得午餐就餐人数*/
	public void getLunchNum(String token,JsonHttpResponseHandler backcall){
		RequestParams params = new RequestParams();
		params.put("token", token);
		client.post(context, Url.getLunchNum, params, backcall);
	}

	/**离线状态下获取取餐信息*/
	public void backupgetOrders(String token,JsonHttpResponseHandler backcall){
		RequestParams params = new RequestParams();
		params.put("token", token);
		client.post(context, Url.backupgetOrders, params, backcall);
	}

	/**获取卡号*/
	public void getCards(String token,JsonHttpResponseHandler backcall){
		RequestParams params = new RequestParams();
		params.put("token", token);
		client.post(context, Url.backupgetCard, params, backcall);
	}

	/**离线状态下提交订单信息*/
	public void backupdealOrder(String token, String data, int status,
								JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("status", status);
		params.put("token", token);
		params.put("data", data);
		client.post(context, Url.backupdealOrder, params, backcall);
	}
	/**紧急状态取餐处理*/
	public void backupdealSorder(String token, String data, int status,
								 JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("status", status);
		params.put("token", token);
		params.put("data", data);
		client.post(context, Url.backupdealSorder, params, backcall);
	}
}
